package com.project.controller;

import com.project.bean.SellCarBean;
import com.project.bean.UserBean;
import com.project.service.ISellCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("sellCar")
@Api(tags = "销售车")
public class SellCarController {
    @Autowired
    private ISellCarService sellCarService;
    @ApiOperation(value = "按用户id查询销售车信息")
    @RequestMapping("findAll")
    public List<SellCarBean> findAll(HttpServletRequest req) {
        UserBean userBean = (UserBean)req.getSession().getAttribute("loginUser");
        return sellCarService.findAll(userBean.getUserId());
    }
    @ApiOperation(value = "添加销售车记录")
    @RequestMapping("add")
    public String add(String productId,HttpServletRequest req){
        UserBean userBean = (UserBean)req.getSession().getAttribute("loginUser");
        sellCarService.add(productId, userBean.getUserId());
        return "ok";
    }
    @ApiOperation(value = "根据销售信息id，删除销售车记录")
    @RequestMapping("del")
    public String del(Integer sellCarId){
        sellCarService.del(sellCarId);
        return "ok";
    }
    @ApiOperation(value = "修改销售商品数量")
    @RequestMapping("updateNum")
    public String updateNum(Integer sellCarId,Integer num){
        sellCarService.updateNum(sellCarId,num);
        return "ok";
    }
}
